import com.alibaba.druid.util.JdbcUtils;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Auther: GongXl
 * @Date: 028 17:28
 * @Description:
 */
public class Test {
    private static Logger logger = Logger.getLogger(Test.class);
    public static void main(String[] args) {
        // System.out.println("This is println message.");

        // 记录debug级别的信息
        logger.debug("This is debug message.");
        // 记录info级别的信息
        logger.info("This is info message.");
        // 记录error级别的信息
        logger.error("This is error message.");

    }

    /**
     * @Author GongXl
     * @Description 数据源测试
     * @Date 029 9:10
     * @Param []
     * @return void
     **/
    public static void test_queryTimeout() throws Exception {
        ApplicationContext context = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
        DataSource dataSource = (DataSource)context.getBean("dataSource");
        Connection conn = dataSource.getConnection();

        String sql = "SELECT * FROM e_user";
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setQueryTimeout(1);
        ResultSet rs = stmt.executeQuery();
        JdbcUtils.printResultSet(rs);
        rs.close();
        stmt.close();
        conn.close();

//        Connection conn = dataSource.getConnection();
//        String sql = "SELECT 'x' FROM DUAL";
//        PreparedStatement stmt = conn.prepareStatement(sql);
//        stmt.setQueryTimeout(1);
//        ResultSet rs = stmt.executeQuery();
//        JdbcUtils.printResultSet(rs);
//        rs.close();
//        stmt.close();
//        conn.close();
    }
}